

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.hre.db.dao.EmpEducationDAO;
import com.edu.hre.db.dao.EmpWorkExperienceDAO;
import com.edu.hre.db.dto.HreEmpEducation;
import com.edu.hre.db.dto.HreEmpWorkExperience;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

/**
 * Servlet implementation class EducationServlet
 */
public class EducationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public EducationServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			response.setContentType("text/html; charset=UTF-8");
			int employeeNumber = Integer.parseInt(request
					.getParameter("emp_number"));
			List<HreEmpEducation> education = new EmpEducationDAO()
					.getEducationByEmployeeId(employeeNumber);
			Gson gson = new Gson();
			JsonObject myObj = new JsonObject();
			myObj.addProperty("success", true);
			myObj.add("education", gson.toJsonTree(education));
			myObj.addProperty("totalCount", education.size());
			response.setContentType("text/html");
			response.getWriter().println(myObj.toString());
			response.getWriter().close();
		}
	

}
